﻿using FastCodeGeneration.Core.Framework;
using FastCodeGeneration.Entity;
using FastCodeGeneration.IService;
using FastCodeGeneration.Models;
using FastCodeGeneration.Service;
using Microsoft.AspNetCore.Mvc;

namespace FastCodeGeneration.Controllers
{
    public class TemplateController : Controller
    {
        private readonly ITemplateService _templateService;

        private readonly IProjectService _projectService;

        public TemplateController(ITemplateService templateService, IProjectService projectService)
        {
            _templateService = templateService;
            _projectService = projectService;
        }

        public IActionResult Index()
        {
            var projectList = _projectService.SelectAll();

            return View(projectList);
        }

        public IPage<Template> GetList(int pageIndex, int pageSize)
        {
            var page = new Page<Template> { PageIndex = pageIndex, PageSize = pageSize };
            _templateService.SelectPage(page, null);
            return page;
        }

        public IPage<Template> GetCondition(Condition condition)
        {
            var page = _templateService.SelectByCondition(condition);
            return page;
        }

        public IActionResult AddOrEdit(int id)
        {
            var template = _templateService.SelectById(id) ?? new Template();
            return View(template);
        }
        public AjaxResult Save(Template template)
        {
            bool res = _templateService.Save(template);
            return new AjaxResult { Code = 200, Message = "保存成功", Data = template };
        }

        [HttpDelete]
        public IActionResult Delete(int id)
        {
            return View();
        }


    }
}
